package com.ifcreate.infowell.client;

import com.ifcreate.infowell.common.annotation.CNotBlank;
import com.ifcreate.infowell.common.annotation.CNotNull;
import com.ifcreate.infowell.common.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author chenzedeng
 * @Email yustart@foxmail.com
 * @Create 2020-10-26 5:42 下午
 */
@RestController
@RequestMapping("/info-wall/api/client")
public class ClientController {

    @Autowired
    private ClientNodeService nodeService;


    /**
     * 获取首页节点数据
     *
     * @param type
     * @param date
     * @param size
     * @return
     */
    @RequestMapping("/getRootNode")
    public JsonResult getRootNode(@CNotNull Integer type, String date, @RequestParam(value = "size", defaultValue = "17") Integer size) {
        return nodeService.getRootNode(type, date, size, null);
    }


    /**
     * 模糊匹配
     *
     * @param search
     * @return
     */
    @RequestMapping("/searchNode")
    public JsonResult searchNode(@CNotBlank String search) {
        return nodeService.getRootNode(null, null, null, search);
    }

    /**
     * 获取时间的间隔
     *
     * @return
     */
    @RequestMapping("/getTimeInterval")
    public JsonResult getTimeInterval() {
        return nodeService.getTimeInterval();
    }


    /**
     * 添加点击的次数
     *
     * @param id
     * @return
     */
    @PostMapping("/addClickCount")
    public JsonResult addClickCount(@CNotNull Long id) {
        return nodeService.addClickCount(id);
    }

    /**
     * 返回热门
     *
     * @param size
     * @return
     */
    @RequestMapping("/getHostNameList")
    public JsonResult getHostNameList(@RequestParam(value = "size", defaultValue = "5") Integer size) {
        return nodeService.getHostNameList(size);
    }
}
